<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h3>数据类型</h3>
		<ul>
			<li>JavaScript数据类型分为基本类型和引用类型。</li>
			<li>基本类型：Null, Undefined, Boolean, Number, String</li>
			<li>引用类型：Object, Array等</li>
			<li><button onclick="funcTest1()">运行例子</button></li>
		</ul>
		<script>
			function funcTest1(){
				var i = 10;
				var j = i;		// i和j分别占据两块不同内存，虽然值都是10
				i = 100;
				console.log(j); // 修改了i，但j并不受影响
				
				var a = {id:1001, name:"jerry"};		// a是引用类型
				var b = a;		// b指向a
				b.id = 1002;
				b.name = "jam";
				console.log(a.id + ":" + a.name);		// a的值与b保持一致
			}
		</script>
	
		<h3>函数参数传递</h3>
		<ul>
			<li>函数调用时，一定存在实参对形参的赋值</li>
			<li>赋值时，遵循基本数据类型之间的值拷贝，以及引用类型之间的引用拷贝原则</li>
			<li>在函数内部修改参数的引用指向，是没有作用的</li>
			<li><button onclick="funcTest2()">运行例子</button></li>
		</ul>
		<script>
			function increaseValue(data){
				data = data + 1;
			}
			function increaseObject(obj){
				obj.count = obj.count + 1;
			}
			function changeReference(obj){
				obj = {count:11};
				// 或者：
				//obj = new Object;
				//obj.count = 11;
			}
			function funcTest2(){
				var i = 10;
				increaseValue(i);
				console.log(i);
				
				var a = {count:10};
				increaseObject(a);
				console.log(a.count);
				
				var b = {count:10};
				changeReference(b);
				console.log(b.count);
			}
		</script>
	
		<h3>判断类型</h3>
		<ul>
			<li>typeof关键字可用于返回字符串形式的类型名称</li>
			<li>typeof作用于引用类型时，永远返回object</li>
			<li>instanceof关键字更适于引用类型</li>
			<li><button onclick="funcTest3()">运行例子</button></li>
		</ul>
		<script>
			function funcTest3(){
				var s = "Nicholas";
				var b = true;
				var i = 22;
				var u;
				var n = null;
				var o = new Object();
				var arr = [1,2,3,4,5];
				var reg = /'d{3}'/;
				console.log(typeof s); //string
				console.log(typeof i); //number
				console.log(typeof b); //boolean
				console.log(typeof u); //undefined
				console.log(typeof n); //object
				console.log(typeof o); //object
				console.log(typeof funcTest3);
				console.log(typeof arr);
				console.log(arr instanceof Array);
				console.log(typeof reg);
				console.log(reg instanceof RegExp);
			}
		</script>
	</body>
</html>
